import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";

import Page from "./page";

const Router = () => {
  // 递归路由
  const mapRouter = (routes) => {
    return routes.map((item, idx) => {
      return item.path ? (
        <Route key={idx} path={item.path} element={item.element}>
          {item.children && mapRouter(item.children)}
        </Route>
      ) : (
        <Route
          key={idx}
          path={item.from}
          element={<Navigate to={item.to} />}
        ></Route>
      );
    });
  };

  return (
    <BrowserRouter>
      <Routes>
        {mapRouter(Page)}
        {/* <Route path="/main" element={<Main/>}>
            <Route path="/main/my" element={<My/>} />
        </Route>
        <Route path="/login" element={<Login/>} /> */}
      </Routes>
    </BrowserRouter>
  );
};

export default Router;
